package com.dlnu.sujiwords.controller;

import com.dlnu.sujiwords.domain.client.AjaxResult;
import com.dlnu.sujiwords.domain.client.RememberWordsParameter;
import com.dlnu.sujiwords.domain.pojo.EnWords;
import com.dlnu.sujiwords.domain.client.SeaTableDataParameter;
import com.dlnu.sujiwords.domain.client.SelTableDataParameter;
import com.dlnu.sujiwords.service.IEnWordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@CrossOrigin
@RequestMapping("/SuJiWords/enWords")
public class EnWordsController {
    @Resource
    private IEnWordsService ienWordsService;

    @GetMapping("/ENToCH/{English}")
    public AjaxResult translateEnglish(@PathVariable("English") String English){
        return ienWordsService.EnToCh(English);
    }
    @GetMapping("/CHToEN/{Chinese}")
    public AjaxResult translateChinese(@PathVariable("Chinese") String Chinese){
        return ienWordsService.ChToEn(Chinese);
    }
    @RequestMapping("/selTableWords")
    public AjaxResult selTableWords(@RequestBody SelTableDataParameter sel){
        System.out.println(sel);
        return ienWordsService.selTableWords(sel.getTable(),sel.getPageNum(),sel.getPageSize());
    }
    @RequestMapping("/searchWords")
    public AjaxResult searchWords(@RequestBody SeaTableDataParameter sea){
        System.out.println(sea.getWord());
        return ienWordsService.searchWords(new EnWords(sea.getWord(),sea.getTranslation()),sea.getTable(),sea.getPageNum(),sea.getPageSize());
    }
   @RequestMapping("/rememberWords")
    public AjaxResult rememberWords(@RequestBody RememberWordsParameter rememberWordsParameter){
       System.out.println(rememberWordsParameter);
        return ienWordsService.remberWords(rememberWordsParameter.getTable(),rememberWordsParameter.getHasRememberWordsNum(),rememberWordsParameter.getWillRememberWordsNum());
   }
}
